import axios from "axios";
import router from '@/router/index';
import { ElMessage } from 'element-plus'

//设置公共的参数
const commonParams = axios.create({
    baseURL: "http://localhost:8080",
    //timeout: 1000
});

// //响应拦截器
commonParams.interceptors.response.use(response => {
    var data = response.data;
    var status = data.status;
    if (status === "200") {
        return response;
    } else if (status === "401") {
        ElMessage.error(data.message);
        //跳转到登录页面
        router.replace("/login");
        //拒绝后续操作
        return Promise.reject(data.message);
    }
})

export default commonParams;


